//
//  MYLoginBaseTextFieldCell.swift
//  MuYing
//
//  Created by tbb on 2019/7/19.
//  Copyright © 2019 TBB. All rights reserved.
//

import UIKit

class MYLoginBaseTextFieldCell: YQTableViewBaseCell,UITextFieldDelegate {
    
    lazy var leftIcon: UIImageView = {
        let leftIcon = UIImageView(image: UIImage(named: "Login_Phone_select_icon"));
        return leftIcon;
    }()
    
    @objc lazy var textField = { () -> UITextField in
        let textField = UITextField();
        textField.textColor = UIColorFromHex(rgbValue: 0xCBCBCB);
        textField.font = UIFont.systemFont(ofSize: 14)
        textField.delegate = self;
        textField.tintColor = appThemeColor;
        textField.returnKeyType = .done;//UIReturnKeyDone
        return textField;
    }()
    
    lazy var lineView = { () -> UIView in
        let lineView = UIView();
        lineView.backgroundColor = UIColorFromHex(rgbValue: 0xE7E7E7);
        return lineView;
    }()
    
    @objc var placeholderStr:String? {
        willSet {
            let attributes = [
                NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15, weight: .medium),
                NSAttributedString.Key.foregroundColor:UIColorFromHex(rgbValue: 0xCBCBCB)
            ];
            
            let attributedString = NSMutableAttributedString(string: newValue!, attributes: attributes)
            
            self.textField.attributedPlaceholder = attributedString.copy() as? NSAttributedString;
            
        }
    }
    
    
    @objc var leftIconImage:UIImage? = nil {
//        willSet{
//        }
        didSet{
            self.leftIcon.image = leftIconImage;
        }
    }
    
    override func layoutSubviews() {
        super.layoutSubviews();
        self.contentView.addSubview(self.leftIcon);
        self.leftIcon.mas_makeConstraints { (make) in
            make?.bottom.mas_equalTo()(-4);
            make?.left.mas_equalTo()(36);
            make?.size.mas_equalTo()(CGSize(width: 20, height: 20));
        }
        
        self.contentView.addSubview(self.textField);

        self.textField.mas_makeConstraints { (make) in
            make?.bottom.mas_equalTo()(-4);
            make?.left.mas_equalTo()(self.leftIcon.mas_right)?.mas_equalTo()(12);
            make?.right.mas_equalTo()(-36);
            make?.height.mas_equalTo()(21);
        }
        
        
        self.contentView.addSubview(self.lineView);
        self.lineView.mas_makeConstraints { (make) in
            make?.bottom.mas_equalTo()(0)
            make?.left.mas_equalTo()(30);
            make?.right.mas_equalTo()(-30);
            make?.height.mas_equalTo()(1);
        }

        
    }
    
    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        return true;
    }
    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }

}
